package net.zdreamer.shunyi.ui.login;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import net.zdreamer.shunyi.R;
import net.zdreamer.shunyi.ui.fragment.LogInFragment;
import net.zdreamer.shunyi.ui.fragment.ShoujiLogInfragment;


public class LogInActivity extends FragmentActivity implements View.OnClickListener {
    private TextView title_content;
    private ImageView leftimg, rightimg;
    private RelativeLayout titlback;
    private LinearLayout pubtonglogin, shoujilogin, putongback, shoujiloninback;
    private boolean ischecked = true;
    private Intent intent;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_log_in2);
        addfragment(new LogInFragment());
        init();
    }

    @Override
    public void onAttachFragment(Fragment fragment) {
        super.onAttachFragment(fragment);

    }

    private void addfragment(Fragment fragment) {
        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();

        ft.replace(R.id.loginfragment, fragment);
        ft.commit();
    }

    private void init() {
        title_content = (TextView) findViewById(R.id.title_content);
        title_content.setText("登录");
        title_content.setTextColor(getResources().getColor(R.color.white));

        titlback = (RelativeLayout) findViewById(R.id.title_item);
        titlback.setBackgroundResource(R.drawable.newsbiaoti);

        leftimg = (ImageView) findViewById(R.id.leftimg);
        rightimg = (ImageView) findViewById(R.id.right_image);
        leftimg.setOnClickListener(this);
        rightimg.setOnClickListener(this);
        leftimg.setImageResource(R.drawable.backimg);
        rightimg.setImageResource(R.drawable.regist);

        pubtonglogin = (LinearLayout) findViewById(R.id.putongdenglu);
        shoujilogin = (LinearLayout) findViewById(R.id.shoujidenglu);
        putongback = (LinearLayout) findViewById(R.id.putongback);
        shoujiloninback = (LinearLayout) findViewById(R.id.shoujiback);
        pubtonglogin.setOnClickListener(this);
        shoujilogin.setOnClickListener(this);

    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.putongdenglu:
                ischecked = true;
                addfragment(new LogInFragment());
                setbackground();
                break;
            case R.id.shoujidenglu:
                ischecked = false;
                addfragment(new ShoujiLogInfragment());
                setbackground();
                break;
            case R.id.leftimg:
                this.finish();
                break;
            case R.id.right_image:
                intent = new Intent(LogInActivity.this, RegistActivity.class);
                startActivity(intent);
                break;
            default:
                break;
        }


    }

    public void setbackground() {
        if (ischecked) {
            putongback.setVisibility(View.VISIBLE);
            shoujiloninback.setVisibility(View.INVISIBLE);
        } else {
            System.out.println("隐藏----");
            putongback.setVisibility(View.INVISIBLE);
            shoujiloninback.setVisibility(View.VISIBLE);
        }
    }
}
